<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/20
 * Time: 10:24
 */
namespace app\wechat\controller;

use app\wechat\service\CategoryService;
use think\Request;

class category
{
    private $per_page;

    public function __construct()
    {
        $this->per_page = config('wx_config')['per_page'];
    }

    /**
     * @param Request $request
     * @return \think\response\Json
     * 获取分类列表
     */
    public function getCategoryList(Request $request)
    {
        $page = $request->post('page', '1', 'int');
        $limit = ($page - 1) * $this->per_page . ',' . $this->per_page;
        $list = CategoryService::getCategoryDetail($limit);
        $total_page = ceil($list['total'] / $this->per_page);
        $next_page = ($page >= $total_page) ? $total_page : bcadd($page, 1);
        $previous_page = ($page <= 1) ? $page : bcsub($page, 1);
        $list['per_page'] = $this->per_page;
        $list['page'] = $page;
        $list['next_page'] = $next_page;
        $list['previous_page'] = $previous_page;
        $list['total_page'] = $total_page;
        return json($list);
    }
}